package com.momo.seckilling.service;

import com.momo.seckilling.dao.ShopDao;
import com.momo.seckilling.entity.ShopInfo;
import com.momo.seckilling.form.ShopApplyForm;
import com.momo.seckilling.form.ShopSearchForm;
import com.momo.seckilling.vo.ShopInfoCondition;
import com.momo.seckilling.vo.ShopInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by li on 2019/2/23.
 */
@Service
public class ShopService {
    @Autowired
    private ShopDao shopDao;

    public void saveShopInfo(ShopApplyForm shopApplyForm){
        ShopInfo shopInfo = new ShopInfo();
        shopInfo.setMerchantid(shopApplyForm.getMerchantid());
        shopInfo.setProvince(shopApplyForm.getProvince());
        shopInfo.setCity(shopApplyForm.getCity());
        shopInfo.setBusinessLicense(shopApplyForm.getBusinessLicense());
        shopInfo.setShopName(shopApplyForm.getShopName());
        shopInfo.setShopDescription(shopApplyForm.getShopDescription());
        shopInfo.setShopBussinessScope(shopApplyForm.getShopBussinessScope());
        shopInfo.setState(0);
        shopInfo.setCreateTime(new Date());
        shopDao.saveShopInfo(shopInfo);
    }

    public List<ShopInfo> listShopInfoBy(ShopSearchForm shopSearchForm){

        ShopInfoVo shopInfoVo = new ShopInfoVo();
        ShopInfoCondition shopInfoCondition = new ShopInfoCondition();
        if(StringUtils.isNotBlank(shopSearchForm.getShopName())){
            shopInfoCondition.setShopName(shopSearchForm.getShopName());
        }
        if(StringUtils.isNotBlank(shopSearchForm.getState())){
            shopInfoCondition.setState(Integer.valueOf(shopSearchForm.getState().trim()));
        }
        shopInfoVo.setShopInfoCondition(shopInfoCondition);
        return shopDao.listShopInfoBy(shopInfoVo);
    }

    public void updateInfoBy(ShopInfo shopInfo){
        shopDao.updateInfoBy(shopInfo);
    }
}
